package com.mycinema.aop;

import java.awt.Point;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

//通知类
@Component  //普通的类
@Aspect     //切面
public class MyAdvice {
	
	@Pointcut("execution(* com.mycinema.biz.impl.*.*(..))")
	public void pc1()
	{		
	}
	
	//@Before("execution(* com.mycinema.biz.impl.*.*(..)")
	//前置通知
	@Before("pc1()")
	public void doBefore(JoinPoint jp)
	{
		System.out.println("====前置通知====");
		//方法签名
		System.out.println("---方法名："+jp.getSignature());
		//获取要执行的方法的参数
		Object[] args=jp.getArgs();
	    System.out.println("kind:"+jp.getKind());
	    System.out.println("getThis:"+jp.getThis());
		for (Object object : args) {
			System.out.println("---参数:"+object);
		}
	}
	//后置通知
	public void doAfter()
	{
		System.out.println("====后置通知====");
	}
	//返回后通知
	public void doAfterReturn(Object returnVal)
	{
		System.out.println(".....返回后通知...");
		System.out.println(".....返回值="+returnVal+"....");
	}
	//环绕通知
	public Object doAround(ProceedingJoinPoint jPoint) throws Throwable
	{
		System.out.println("====开始环绕====");
		//调用目标方法
		Object object=jPoint.proceed(jPoint.getArgs());
		System.out.println("====结束环绕====");
		return object;
	}
	
	//异常后通知
	public void doAfterThrow(Throwable ex)
	{
		System.out.println("----异常后通知----");
		System.out.println("*****异常:"+ex.getMessage()+"*****");
	}
}
